var text = "";
var smileyTags = new Array (
  ":)", ":(", ":D", "8D", ":|", ":P", ":S", ";)", "B)", 
  ":8)", ":O)", ":[", "xx(", "|)", ":X", ":^)", ":\~)", ":?)" );

function insertSmileyTag(smileyTag) {
    AddText(smileyTag);
}

function getActiveText(selectedtext) { 
	text = (document.all) ? document.selection.createRange().text : document.getSelection();
	if (selectedtext.createTextRange) {	
    selectedtext.caretPos = document.selection.createRange().duplicate();	
  }
	return true;
}

function AddText(NewCode) {
	if (document.form.body.createTextRange && document.form.body.caretPos) {
		var caretPos = document.form.body.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
	} 
  else {
		document.form.body.value+=NewCode
	}
	setfocus();
}

function setfocus() {
  document.form.body.focus();
}

function email() {
	AddTxt="[email]"+text+"[/email]";
	AddText(AddTxt);
}

function suptext() {
	AddTxt="[sup]"+text+"[/sup]";
	AddText(AddTxt);	
}

function subtext() {
	AddTxt="[sub]"+text+"[/sub]";
	AddText(AddTxt);	
}

function bold() {
	AddTxt="[b]"+text+"[/b]";
	AddText(AddTxt);	
}

function italicize() {
	AddTxt="[i]"+text+"[/i]";
	AddText(AddTxt);
}

function quote() {
	AddTxt="[quote]"+text+"[/quote]";
	AddText(AddTxt);
}

function showsize(size) {
	AddTxt="[size="+size+"]"+text+"[/size]";
	AddText(AddTxt);
	document.form.size.value = "";
}

function showcolor(color) {
	AddTxt="[color="+color+"]"+text+"[/color]";
	AddText(AddTxt);
	document.form.color.value = "";
}

function center() {
	AddTxt="[center]"+text+"[/center]";
	AddText(AddTxt);
}

function hyperlink() {
	AddTxt="[url]"+text+"[/url]";
	AddText(AddTxt);
}

function image() {
	AddTxt="[img]"+text+"[/img]";
	AddText(AddTxt);
}

function showcode() {
	AddTxt="[code]"+text+"[/code]";
	AddText(AddTxt);
}

function underline() {
	AddTxt="[u]"+text+"[/u]";
	AddText(AddTxt);
}

function moreColor() {
    var nw = window.open("$cfg{'nonCgiPath'}/color.html", "_blank", "width=350,height=320,resizable=no,scrollBars=yes,menuBar=no,directories=no,toolBar=no,location=No,status=No");
}